class Solution {
    public int sumOfLeftLeaves(TreeNode root) {
        return sumLeft(root, false);
    }

    public int sumLeft(TreeNode node, boolean isLeft) {
        if (node == null) return 0;
        // 是叶子且在左边
        if (node.left == null && node.right == null && isLeft) {
            return node.val + sumLeft(node.right, false);
        }
        // 不是叶子或不在左边
        return sumLeft(node.left, true) + sumLeft(node.right, false);
    }
}
